﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using AssetManageSystem.Model.AssetManage;
using AssetManageSystem.Model.OrgManage;
using AssetManageSystem.Model.Enum;


namespace AssetManageSystem.ViewModel.AssetManage.AssetInfoVMs
{
    public partial class AssetInfoListLiteVM : BasePagedListVM<AssetInfoLite_View, AssetInfoSearcher>
    {
        protected override List<GridAction> InitGridAction()
        {
                return new List<GridAction>();
        }
        protected override IEnumerable<IGridColumn<AssetInfoLite_View>> InitGridHeader()
        {
                return new List<GridColumn<AssetInfoLite_View>>{
                this.MakeGridHeader(x => x.AsName),
                this.MakeGridHeader(x => x.AsCode),
                this.MakeGridHeader(x => x.BuyTime),
                this.MakeGridHeader(x => x.UseDepId).SetHide(true),
                this.MakeGridHeader(x => x.UsePeopleId).SetHide(true),
                this.MakeGridHeader(x => x.Status)
        };
        }

        public override IOrderedQueryable<AssetInfoLite_View> GetSearchQuery()
        {
            var query = DC.Set<AssetInfo>()
                //.CheckWhere(Searcher.IsScrap,x=>x.Status!=AsStatusEnum.Scrap)
                .CheckContain(Searcher.AsName, x => x.AsName)
                .CheckEqual(Searcher.TypeId, x => x.TypeId)
                .CheckBetween(Searcher.BuyTime?.GetStartTime(), Searcher.BuyTime?.GetEndTime(), x => x.BuyTime, includeMax: false)
                .CheckEqual(Searcher.UsePeopleId, x => x.UsePeopleId)
                .CheckEqual(Searcher.UseDepId, x => x.UseDepId)
                .CheckEqual(Searcher.Status, x => x.Status)
                .CheckEqual(Searcher.Id, x => x.ID)
                .Select(x => new AssetInfoLite_View
                {
                    ID = x.ID,
                    AsName = x.AsName,
                    AsCode = x.AsCode,
                    BuyTime = x.BuyTime,
                    UserName_view = x.UsePeople.UserName,
                    DepName_view = x.UseDep.DepName,
                    UseDepId = x.UseDep.ID,
                    UsePeopleId= x.UsePeopleId,
                    Status = x.Status
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class AssetInfoLite_View : AssetInfo
    {
        [Display(Name = "使用人")]
        public String UserName_view { get; set; }
        [Display(Name = "使用部门")]
        public String DepName_view { get; set; }
    }
}
